<!--
 * @Descripttion:首页
 * @version:
 * @Author: ada.wu
 * @Date:2024-03-11 11:26:44
 * @LastEditors: ada.wu
 * @LastEditTime: 2024-04-09 20:36:24
-->
<template>
  <div class="hub">
    <img src="/@/assets/exam/home.png" class="home-img">
    <div class="round2">
      <img src="/@/assets/exam/home2.svg">
    </div>
    <van-skeleton title :row="3" v-if="isQuery" />
    <van-empty v-if="listData.length==0&&!isQuery" description="暂无数据…" :image="getAssets('empty.svg')" />
    <div class="t-xl t-m-x text-base p-l-lg m-l-lg p-t-lg  m-t-sm" v-for="(item,index) in listData" :key="index" @click="goUrl(item)">
      •{{item.activityName}}
    </div>
    <div class="round1">
      <img src="/@/assets/exam/home1.svg">
    </div>
    <!-- <div class="fixed_bottom p-tb t-r">
      <van-button round plain size="small" color="#28A3AF" @click="goBack">返回</van-button>
    </div> -->
  </div>
</template>
<script lang="ts">
//util
import { onMounted, reactive, toRefs, ref, nextTick } from "vue";
import { useRoute, useRouter } from "vue-router";
import { PageEnum } from "/@/enums/pageEnum";
import { getUrlKey } from "/@/util";
import { RSAdecrypt } from "/@/util/jsencrypt";
import { useStore } from "/@/store";
export default {
  name: "home",
  components: {},
  setup() {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    let { valuatorUserId = "", activityId = "" } = route.query;

    let _query = route.fullPath.split("?")[1];
    // url 加密了

    let _url = `?${RSAdecrypt(_query)}` as any;
    const _valuatorUserId = getUrlKey("valuatorUserId", _url);
    const _activityId = getUrlKey("activityId", _url);

    if (_activityId) activityId = _activityId;
    if (_valuatorUserId) valuatorUserId = _valuatorUserId;
    // console.log("_url--", _url);
    // console.error("valuatorUserId--", valuatorUserId);
    // console.error("activityId--", activityId);
    // console.log("fullPath==", route.fullPath.split("?")[1]);
    // console.error("解密:", RSAdecrypt(_query));
    const state = reactive({
      isQuery: false,
      listData: <any>[],
    });

    onMounted(async () => {
      if (activityId) {
        state.isQuery = true;
        let res = await store.dispatch("exam/getActivityDetail", {
          activityId,
        });
        state.isQuery = false;
        if (res && res.succ) {
          state.listData = [res.content];
        }
      }
    });

    function goUrl(item: any) {
      let path = "";
      let query = {
        activityId: item.activityId,
        valuatorUserId, //评价者
      };
      const { activityDetail, projectDetail } = item;
      if (activityDetail) {
        path = PageEnum.WELCOME; //欢迎页
      } else {
        if (projectDetail) {
          path = PageEnum.REMIND; //作答页
        } else {
          path = PageEnum.EMPLOYEE; //人员
        }
      }
      router.push({
        path,
        query,
      });
    }
    const goBack = () => {
      router.back();
    };
    return {
      ...toRefs(state),
      goUrl,
      goBack,
    };
  },
};
</script>

<style lang="scss" scoped>
.hub {
  background: url("/@/assets/exam/home-bg.png") no-repeat;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  max-width: 700px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.round2 {
  text-align: left;
  img {
    width: 182px;
  }
}
.home-img {
  width: 280px;
  position: absolute;
  bottom: -6px;
  left: 30px;
  z-index: 2;
}
.round1 {
  position: absolute;
  bottom: -4px;
  left: 0;
  z-index: 1;
  img {
    width: 260px;
  }
}

::v-deep(.van-button--plain) {
  width: 78px;
  background: transparent;
  font-size: 16px;
}
</style>
